From ad8ae4055ea9cc5ec61aace254c66c840c1bb1e6 Mon Sep 17 00:00:00 2001 From: Emmanuel Ackaouy Date: Mon, 25 Sep 2006 16:31:02 +0100 Subject: [PATCH] Make dom0_vcpus_pin a platform independant option. By default, it's off. When enabled on the command line, it causes dom0's VCPUs to be pinned to their respective physical CPUs at creation time. Once pinned, they can never be moved. ALso cleanup VCPU initialization of scheduler parameters. Signed-off-by: Emmanuel Ackaouy --- docs/src/user.tex | 2 ++ xen/arch/ia64/xen/domain.c | 6 +---- xen/arch/ia64/xen/xensetup.c | 8 ------- xen/common/domain.c | 6 +---- xen/common/schedule.c | 43 +++++++++++++++++++++++++++++------- xen/include/xen/sched.h | 2 +- 6 files changed, 40 insertions(+), 27 deletions(-) diff --git a/docs/src/user.tex b/docs/src/user.tex index 52c2d746b2..6b4e5cfa72 100644 --- a/docs/src/user.tex +++ b/docs/src/user.tex @@ -3208,6 +3208,8 @@ editing \path{grub.conf}. respectively; if no suffix is specified, the parameter defaults to kilobytes. In previous versions of Xen, suffixes were not supported and the value is always interpreted as kilobytes. +\item [ dom0\_vcpus\_pin ] Pins domain 0 VCPUs on their respective + physical CPUS (default=false). \item [ tbuf\_size=xxx ] Set the size of the per-cpu trace buffers, in pages (default 0). \item [ sched=xxx ] Select the CPU scheduler Xen should use. The diff --git a/xen/arch/ia64/xen/domain.c b/xen/arch/ia64/xen/domain.c index 17ca6ff40e..2073fd52c7 100644 --- a/xen/arch/ia64/xen/domain.c +++ b/xen/arch/ia64/xen/domain.c @@ -54,7 +54,6 @@ unsigned long dom0_align = 64*1024*1024; static unsigned int dom0_max_vcpus = 1; integer_param("dom0_max_vcpus", dom0_max_vcpus); -extern int opt_dom0_vcpus_pin; extern unsigned long running_on_sim; extern char dom0_command_line[]; @@ -1021,12 +1020,9 @@ int construct_dom0(struct domain *d, dom0_max_vcpus = MAX_VIRT_CPUS; printf ("Dom0 max_vcpus=%d\n", dom0_max_vcpus); - for ( i = 1; i < dom0_max_vcpus; i++ ) { + for ( i = 1; i < dom0_max_vcpus; i++ ) if (alloc_vcpu(d, i, i) == NULL) printf ("Cannot allocate dom0 vcpu %d\n", i); - else if (opt_dom0_vcpus_pin) - d->vcpu[i]->cpu_affinity = cpumask_of_cpu(i); - } /* Copy the OS image. */ loaddomainelfimage(d,image_start); diff --git a/xen/arch/ia64/xen/xensetup.c b/xen/arch/ia64/xen/xensetup.c index 4b9095c38d..44a4c51085 100644 --- a/xen/arch/ia64/xen/xensetup.c +++ b/xen/arch/ia64/xen/xensetup.c @@ -48,10 +48,6 @@ extern void mem_init(void); extern void init_IRQ(void); extern void trap_init(void); -/* opt_dom0_vcpus_pin: If true, dom0 VCPUs are pinned. */ -unsigned int opt_dom0_vcpus_pin = 0; -boolean_param("dom0_vcpus_pin", opt_dom0_vcpus_pin); - /* opt_nosmp: If true, secondary processors are ignored. */ static int opt_nosmp = 0; boolean_param("nosmp", opt_nosmp); @@ -520,10 +516,6 @@ printk("num_online_cpus=%d, max_cpus=%d\n",num_online_cpus(),max_cpus); 0) != 0) panic("Could not set up DOM0 guest OS\n"); - /* PIN domain0 VCPU 0 on CPU 0. */ - if (opt_dom0_vcpus_pin) - dom0->vcpu[0]->cpu_affinity = cpumask_of_cpu(0); - if (!running_on_sim) // slow on ski and pages are pre-initialized to zero scrub_heap_pages(); diff --git a/xen/common/domain.c b/xen/common/domain.c index 1138a9aa5e..2dde26eb75 100644 --- a/xen/common/domain.c +++ b/xen/common/domain.c @@ -82,20 +82,16 @@ struct vcpu *alloc_vcpu( v->domain = d; v->vcpu_id = vcpu_id; - v->processor = cpu_id; v->vcpu_info = &d->shared_info->vcpu_info[vcpu_id]; spin_lock_init(&v->pause_lock); - v->cpu_affinity = is_idle_domain(d) ? - cpumask_of_cpu(cpu_id) : CPU_MASK_ALL; - v->runstate.state = is_idle_vcpu(v) ? RUNSTATE_running : RUNSTATE_offline; v->runstate.state_entry_time = NOW(); if ( (vcpu_id != 0) && !is_idle_domain(d) ) set_bit(_VCPUF_down, &v->vcpu_flags); - if ( sched_init_vcpu(v) < 0 ) + if ( sched_init_vcpu(v, cpu_id) < 0 ) { free_vcpu_struct(v); return NULL; diff --git a/xen/common/schedule.c b/xen/common/schedule.c index 61f8f4c3de..0b5ab9501c 100644 --- a/xen/common/schedule.c +++ b/xen/common/schedule.c @@ -37,6 +37,11 @@ extern void arch_getdomaininfo_ctxt(struct vcpu *, static char opt_sched[10] = "credit"; string_param("sched", opt_sched); +/* opt_dom0_vcpus_pin: If true, dom0 VCPUs are pinned. */ +static unsigned int opt_dom0_vcpus_pin; +boolean_param("dom0_vcpus_pin", opt_dom0_vcpus_pin); + + #define TIME_SLOP (s32)MICROSECS(50) /* allow time to slip a bit */ /* Various timer handlers. */ @@ -97,19 +102,38 @@ void vcpu_runstate_get(struct vcpu *v, struct vcpu_runstate_info *runstate) } } -int sched_init_vcpu(struct vcpu *v) +int sched_init_vcpu(struct vcpu *v, unsigned int processor) { - /* Initialise the per-domain timers. */ - init_timer(&v->timer, vcpu_timer_fn, v, v->processor); - init_timer(&v->poll_timer, poll_timer_fn, v, v->processor); + const struct domain * const d = v->domain; + + /* Initialize processor and affinity settings. */ + v->processor = processor; + + if ( is_idle_domain(d) || (d->domain_id == 0 && opt_dom0_vcpus_pin) ) + { + /* + * The idler and potentially dom0 VCPUs are pinned onto their + * respective physical CPUs. + */ + v->cpu_affinity = cpumask_of_cpu(processor); - if ( is_idle_vcpu(v) ) + /* The idle VCPUs takes over their CPUs on creation... */ + if ( is_idle_domain(d) ) + { + per_cpu(schedule_data, v->processor).curr = v; + per_cpu(schedule_data, v->processor).idle = v; + set_bit(_VCPUF_running, &v->vcpu_flags); + } + } + else { - per_cpu(schedule_data, v->processor).curr = v; - per_cpu(schedule_data, v->processor).idle = v; - set_bit(_VCPUF_running, &v->vcpu_flags); + v->cpu_affinity = CPU_MASK_ALL; } + /* Initialise the per-domain timers. */ + init_timer(&v->timer, vcpu_timer_fn, v, v->processor); + init_timer(&v->poll_timer, poll_timer_fn, v, v->processor); + TRACE_2D(TRC_SCHED_DOM_ADD, v->domain->domain_id, v->vcpu_id); return SCHED_OP(init_vcpu, v); @@ -212,6 +236,9 @@ int vcpu_set_affinity(struct vcpu *v, cpumask_t *affinity) cpumask_t online_affinity; unsigned long flags; + if ( v->domain->domain_id == 0 && opt_dom0_vcpus_pin ) + return -EINVAL; + cpus_and(online_affinity, *affinity, cpu_online_map); if ( cpus_empty(online_affinity) ) return -EINVAL; diff --git a/xen/include/xen/sched.h b/xen/include/xen/sched.h index 7e435bf2cf..93abe4e17f 100644 --- a/xen/include/xen/sched.h +++ b/xen/include/xen/sched.h @@ -280,7 +280,7 @@ void new_thread(struct vcpu *d, #define set_current_state(_s) do { current->state = (_s); } while (0) void scheduler_init(void); void schedulers_start(void); -int sched_init_vcpu(struct vcpu *); +int sched_init_vcpu(struct vcpu *v, unsigned int processor); void sched_destroy_domain(struct domain *); long sched_adjust(struct domain *, struct xen_domctl_scheduler_op *); int sched_id(void); -- 2.30.2